package display.threads;

import java.util.concurrent.locks.ReentrantReadWriteLock;

import display.InventoryData;
import display.tabs.ThreadMonitor;

public abstract class MyThread extends Thread {

	private static ThreadMonitor parent;
	InventoryData inv;
	private boolean loop;
	private String status;
	private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
	
	public MyThread(InventoryData in, String name, boolean loops) {
		super(name);
		
		inv = in;
		loop = loops;
	}
	
	@Override
	public final void run() {
		do {
			myRun();
		} while (loop);
	}
	
	public abstract void myRun();
	
	public void setStatus(String stat) {
		lock.writeLock().lock();
		status = stat;
		lock.writeLock().unlock();
	}
	
	public String getStatus() {
		String out;
		lock.readLock().lock();
		out = status;
		lock.readLock().unlock();
		return out;
	}
	
	public void Stop() {
		setStatus("stopping");
		ThreadMonitor.stop(this);
	}

	public void setLoop(boolean l) {
		loop = l;
	}
}
